home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5429 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: open vs fopen?
  5. Date: Fri, 09 Feb 96 23:06:23 GMT
  6. Organization: none
  7. Message-ID: <823907183snz@genesis.demon.co.uk>
  8. References: <uEYFxc9nX8WX083yn@mbnet.mb.ca> <4f7v8u$3s2@unix.sri.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4f7v8u$3s2@unix.sri.com> mklenk@coronacorp.com "Mark Klenk" writes:
  15.  
  16. >Nathan Wild asked:
  17. >>
  18. >>In C, why would one use open and DOS int handles rather than fopen and
  19. >>stdio file handles?
  20. >
  21. >        open() and family are really UNIX-isms that DOS adopted.
  22. >
  23. >        To answer your question, though:
  24. >
  25. >         a)  file I/O through open/close/read/write/lseek is generally
  26. >              unbuffered and therefore in some cases faster, especially
  27. >              in random-access situations
  28.  
  29. That is debatable. Where open etc. can be a win is if you create your own
  30. buffering which is optimised to the code's usage patterns. FILE buffering
  31. isn't bad but it is generalised and may not be optimal for specific
  32. cases.
  33.  
  34. In Unix open() gives you finer control over the file mode and options
  35. not available on fopen. 'int handles' are also used for other system
  36. provided functions such as record locking and dealing with special/device
  37. files. They are probably not as useful in DOS.
  38.  
  39. >         b)  ANSI C only defines fopen/fclose/fread/fwrite/fseek, which
  40. >              by default usually provide buffered, but more portable, I/O
  41.  
  42. Right so if these do the job they are generally the appropriate choice.
  43. They are also generally easier to use since you don't have to worry about
  44. buffering yourself and you get powerful functions like printf. The
  45. bottom line is that since open() isn't part of the C language you can't
  46. use it in 'portable' C code. 
  47.  
  48. >         c)  for sequential access, the f*() functions can improve I/O
  49. >              performance because they generally do read-ahead and
  50. >              write-behind in order to match system block-sizes more
  51. >              closely
  52.  
  53. No, they don't (at least not any of the ones I've come across). To do this
  54. would require asynchronous file I/O. It is almost always the OS that performs
  55. any read-ahead hence both fopen and open style reads get the benefit.
  56.  
  57. -- 
  58. -----------------------------------------
  59. Lawrence Kirby | fred@genesis.demon.co.uk
  60. Wilts, England | 70734.126@compuserve.com
  61. -----------------------------------------
  62.